package gervosou;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.DropMode;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSeparator;

public class VueConsCompteSoc extends Vue {

	/**
	 * 
	 */
	//private static final long serialVersionUID = 5069349224425178639L;
	private JPanel contentPane;

	// a ajouter car la vue est observatrice d'un client
		private ComptePerso _comptesSoc ;
		private JTextField textFieldNum;
		private JTextField textFieldNom;
		private JTextField textFieldAdresse;
		private JTextField textFieldNum2;
		private JTextField textFieldSolde;
		private JButton btnRechercher;
		private JButton btnFermer;
	/**
	 * Create the frame.
	 */
	public VueConsCompteSoc(Controleur controleur) {
		super (controleur);
		setTitle("Consulter un compte societe");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 296, 406);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNumero = new JLabel("Numéro du compte");
		lblNumero.setBounds(12, 12, 119, 15);
		contentPane.add(lblNumero);
		
		textFieldNum = new JTextField();
		textFieldNum.setBounds(170, 10, 42, 19);
		contentPane.add(textFieldNum);
		textFieldNum.setColumns(10);
		
		JLabel lblNom = new JLabel("Nom de la societe");
		lblNom.setBounds(12, 125, 119, 15);
		contentPane.add(lblNom);
		
		JButton btnRechercher = new JButton("Rechercher");		
		btnRechercher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String num = textFieldNum.getText();
				getControleur().consulerCompteSoc(num);}
		});
		
		btnRechercher.setBounds(105, 39, 107, 25);
		contentPane.add(btnRechercher);
		
		JLabel lblAdresse = new JLabel("Adresse");
		lblAdresse.setBounds(12, 183, 61, 15);
		contentPane.add(lblAdresse);
		
		textFieldNom = new JTextField();
		textFieldNom.setEditable(false);
		textFieldNom.setBounds(46, 152, 178, 19);
		contentPane.add(textFieldNom);
		textFieldNom.setColumns(10);
		
		textFieldAdresse = new JTextField();
		textFieldAdresse.setEditable(false);
		textFieldAdresse.setBounds(46, 210, 178, 19);
		contentPane.add(textFieldAdresse);
		textFieldAdresse.setColumns(10);
		
		JLabel lblCompteN = new JLabel("Compte n°");
		lblCompteN.setBounds(12, 263, 76, 17);
		contentPane.add(lblCompteN);
		
		textFieldNum2 = new JTextField();
		textFieldNum2.setEditable(false);
		textFieldNum2.setColumns(10);
		textFieldNum2.setBounds(109, 262, 42, 19);
		contentPane.add(textFieldNum2);
		
		JLabel lblSolde = new JLabel("Solde");
		lblSolde.setBounds(12, 314, 61, 15);
		contentPane.add(lblSolde);
		
		textFieldSolde = new JTextField();
		textFieldSolde.setEditable(false);
		textFieldSolde.setBounds(80, 312, 114, 19);
		contentPane.add(textFieldSolde);
		textFieldSolde.setColumns(10);
		
		JButton btnFermer = new JButton("Fermer");
		btnFermer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsCompteSoc.this);
			}
		});
		btnFermer.setBounds(87, 343, 107, 25);
		contentPane.add(btnFermer);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(12, 83, 264, 8);
		contentPane.add(separator);
	}
	
	public void setEtat (int etat){
		switch (etat) {
		case Vue.initiale: {
			 Object p = null;
			break;
			}
		}
	}
		
	public void alimente(CompteSociete cs){
		int num = cs.getNumero();
		float s = cs.getSolde();
		Societe soc = cs.getSociete();
		String nom = soc.getNom();
		String ad = soc.getAdresse();
		textFieldSolde.setText(String.valueOf(s));
		textFieldNum2.setText(String.valueOf(num));
		textFieldAdresse.setText(ad);
		textFieldNom.setText(nom);
		
	}
}
